﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using OpenExpressApp.Module.WPF;
using OpenExpressApp.Editors;

namespace OpenExpressApp.Module.WPF.Editors
{
    public class GDataGridLookupListColumn : OpenDataGridColumn
    {
        private LookupListPropertyEditor _editor;

        public override IWPFPropertyEditor Editor
        {
            get
            {
                return this._editor;
            }
        }

        public GDataGridLookupListColumn(BusinessObjectPropertyInfo info, IListObjectView view)
            : base(info, view)
        {
            _editor = new LookupListPropertyEditor(this.PropertyInfo, this.View);
        }

        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            TextBlock result = new TextBlock();
            Binding TextBinding = new Binding(PropertyInfo.LookupAttribute.LookupPropertyName + "."
                + ApplicationModel.GetBusinessObjectInfo(PropertyInfo.LookupAttribute.LookupType).TitleInfo.Name);
            result.SetBinding(TextBlock.TextProperty, TextBinding);
            return result;
        }
    }
}
